#include "ground.h"
#include <QtOpenGL/qgl.h>

Ground::Ground()
{
  midaX = 30;
  midaY = 0.5; 
  midaZ = 30;
}

void Ground::Init(double sx, double sz)
{
  midaX = sx; 
  midaZ = sz;
}

void Ground::Render()
{
  glColor3f(0.3, 0.3, 0.3);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, (GLfloat[]) {0.3, 0.3, 0.3});
  glMaterialfv(GL_FRONT, GL_AMBIENT, (GLfloat[]) {0.3, 0.3, 0.3});
  glNormal3f(0,1,0);

  glBegin(GL_QUADS);
      float incrementX = midaX/20;
  float incrementZ = midaZ/20;
  for (float i = incrementX; i <= midaX; i+=incrementX){
      for (float j = incrementZ; j <= midaZ; j+=incrementZ){
          glVertex3f(i-incrementX, 0, j-incrementZ);
          glVertex3f(i-incrementX, 0, j);
          glVertex3f(i, 0, j);
          glVertex3f(i, 0, j-incrementZ);
      }
  }

  glVertex3f(0, -midaY, 0);
  glVertex3f(0, -midaY, midaZ);
  glVertex3f(midaX, -midaY, midaZ);
  glVertex3f(midaX, -midaY, 0);

  glVertex3f(0, 0, 0);
  glVertex3f(0, -midaY, 0);
  glVertex3f(0, -midaY, midaZ);
  glVertex3f(0, 0, midaZ);

  glVertex3f(midaX, 0, 0);
  glVertex3f(midaX, -midaY, 0);
  glVertex3f(midaX, -midaY, midaZ);
  glVertex3f(midaX, 0, midaZ);

  glVertex3f(0, 0, 0);
  glVertex3f(midaX, 0, 0);
  glVertex3f(midaX, -midaY, 0);
  glVertex3f(0, -midaY, 0);

  glVertex3f(0, 0, midaZ);
  glVertex3f(midaX, 0, midaZ);
  glVertex3f(midaX, -midaY, midaZ);
  glVertex3f(0, -midaY, midaZ);

  glEnd();
}


double Ground::MidaX () { return midaX; }

double Ground::MidaY () { return midaY; }

double Ground::MidaZ () { return midaZ; }
